import time
from selenium import webdriver
from selenium.webdriver.common.by import By

# 2.打开浏览器
driver = webdriver.Chrome()
# 2.输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")

# # 3.页面操作
# 定位元素并输入内容
# 属性定位
driver.find_element(By.XPATH,"//input[@name='userA']").send_keys("admin")
driver.find_element(By.XPATH,".//*[@id='passwordA']").send_keys("123456")
driver.find_element(By.XPATH,".//input[@placeholder='请输入密码']").send_keys("123456")
# # 属性和逻辑结合
# driver.find_element(By.XPATH,"//input[@type='button' and @value='prompt']").click()
# 层级和属性定位
# driver.find_element(By.XPATH,"//p[@id='pa']/input[@type='text']").send_keys("admin")
# driver.find_element(By.XPATH,"//p/input[@id='passwordA']").send_keys("admin")

# 元素文本定位
# 语法：//*[text()="文本"]
# driver.find_element(By.XPATH,".//a[text()='百度']").click()

# 局部属性值定位
# 语法：//*[contains(@属性名,"局部属性值")]
# driver.find_element(By.XPATH,".//*[contains(@placeholder,'用户名')]").send_keys("admin")

# 暂停3秒
time.sleep(3)
# 4.关闭/退出浏览器
# 关闭驱动对象
driver.quit()
